const articleService = require("@/server/article");
const { GetFromContext } = require("@/utils/gin_context");
const { successData, sendCode } = require("@/utils/r/result");

const article = {
  async GetFrontList(req, res) {
    successData(res, await articleService.GetFrontList(req.query));
  },
  async GetFrontInfo(req, res) {
    const id = +req.params.id;
    successData(res, await articleService.GetFrontInfo(id));
  },
  async SaveLike(req, res) {
    const articleId = +req.params.article_id;
    const uid = GetFromContext(req, "user_info_id");

    sendCode(res, await articleService.SaveLike(uid, articleId));
  },
  async GetArchiveList(req, res) {
    successData(res, await articleService.GetArchiveList(req.query));
  },
  async Search(req, res) {
    successData(res, await articleService.Search(req.query));
  },
};

module.exports = article;
